<?php
	include 'database.php';
	
	$link = pg_connect("user=".DB_USER." port=".DB_PORT." dbname=".DB_NAME." host=".DB_HOST." password=".DB_PASS);
	
	try
	{
		$sql = "select distinct e.* 
				from estacion e 
				join seccion s on e.id_estacion = s.estacion_id
				join perfil p on s.id_seccion = p.seccion_id
				join perfil_medicion_puntos pmp on p.id_perfil = pmp.perfil_id
				ORDER BY e.nm_nombre";
		
		$result = pg_exec($link, $sql);
		
		$arr = array();
		
		If (!$result) {
			pg_close($link);
			Echo '{success:false}'.$sql;
		}
		else
		{
			while($obj = pg_fetch_object($result)){
				$arr[] = $obj;
			}
			pg_close($link);
			Echo '{success:true,data:'.json_encode($arr).'}';		
		}
	}catch(Exception $e)
	{
		pg_close($link);
		echo '{success:false}';
	}
?>




		